# Maintainer: Santiago Torres-Arias <santiago -> a.o >
# Maintainer: Nick Black <dankamongmen@gmail.com>

pkgname=notcurses
pkgver=3.0.9
pkgrel=3
pkgdesc="Blingful TUI/character graphics library"
url="https://nick-black.com/dankwiki/index.php/Notcurses"
license=('Apache')
arch=('loong64' 'x86_64')
# TODO: package qrcodegen
depends=(
  'gcc-libs'
  'glibc'
)
makedepends=(
  'cmake'
  'doctest'
  'ffmpeg'
  'gpm'
  'libdeflate'
  'libunistring'
  'ncurses'
  'ninja'
  'pandoc'
  'python-build'
  'python-cffi'
  'python-installer'
  'python-pypandoc'
  'python-setuptools'
  'python-wheel'
  'readline'
  'zlib'
)
provides=(libnotcurses++.so libnotcurses.so libnotcurses-core.so)
source=("https://github.com/dankamongmen/notcurses/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha256sums=('e5cc02aea82814b843cdf34dedd716e6e1e9ca440cf0f899853ca95e241bd734')
b2sums=('718a5a36ed17d9118690ffdce3b2233144de0b8421a37429f1a20ae735215a87be9c308876c97d8a5126238fee76e470429837c7f224e8f020c60ad6b88514bd')

build() {
  local cmake_options=(
    -B build
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_BUILD_TYPE=None
    -DUSE_GPM=on
    -DUSE_QRCODEGEN=off
    -GNinja
    -S $pkgname-$pkgver
    -Wno-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build
  cd $pkgname-$pkgver/cffi
  CFLAGS+=" -I$srcdir/$pkgname-$pkgver/include -L$srcdir/build" python -m build --wheel --no-isolation
}

check() {
  ctest --test-dir build --output-on-failure
}

package() {
  depends+=(
    'ffmpeg' 'libavcodec.so' 'libavformat.so' 'libavutil.so' 'libswscale.so'
    'gpm' 'libgpm.so'
    'libdeflate' 'libdeflate.so'
    'libunistring' 'libunistring.so'
    'ncurses' 'libncursesw.so'
    'python-cffi'
  )

  DESTDIR="$pkgdir" cmake --install build
  python -m installer --destdir="$pkgdir" $pkgname-$pkgver/cffi/dist/*.whl
}
